<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body>
<div class="login-logo"><h1>健身房管理系统</h1></div>
<div class="login-box">
    <form class="layui-form layui-form-pane" action="" method="" id="myform">
        <h3>登录你的帐号</h3>
        <label class="login-title" for="username">帐号</label>
        <div class="layui-form-item">
            <label class="layui-form-label login-form"><i class="iconfont">&#xe6b8;</i></label>
            <div class="layui-input-inline login-inline">
                <input type="text" id="username" lay-verify="required" placeholder="请输入你的帐号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <label class="login-title" for="password">密码</label>
        <div class="layui-form-item">
            <label class="layui-form-label login-form"><i class="iconfont">&#xe82b;</i></label>
            <div class="layui-input-inline login-inline">
                <input type="password" id="password" lay-verify="required" placeholder="请输入你的密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <input type="radio" name="role" value="1" title="会员" checked>
        <input type="radio" name="role" value="2" title="教练员">
        <input type="radio" name="role" value="3" title="管理员">
        <div class="form-actions">
            <button type="button" class="btn btn-warning pull-right" onclick="login()">登录</button>
            <div class="forgot">
                <a href="javascript:member_add('注册','${pageContext.request.contextPath}/registers.jsp','','550');">注册</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="#" class="forgot" onclick="layer.msg('敬请期待！')">忘记帐号或者密码</a>
            </div>
        </div>
    </form>
</div>
<script>
    /*用户-注册*/
    function member_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    };

    /*用户-登录，根据选择的权限登录*/
    function login() {
        //获取选择登录的权限
        var check = $("input[name='role']:checked").val();
        //定义路径，根据不同权限发送不同请求
        var urlf = "";
        console.log(check);
        console.log(12);
        if (check==1){
            //会员登录
            urlf = "${pageContext.request.contextPath}/member/login.action";
        }else if (check==2){
            //教练登录
            urlf = "${pageContext.request.contextPath}/coach/login.action";
        }else if (check==3){
            //管理员登录
            urlf = "${pageContext.request.contextPath}/admin/login.action";
        }
        //发送请求
        $.ajax({
            url:urlf,
            type:"post",
            data:{username:$("#username").val(),password:$("#password").val()},
            success:function (date){
                console.log(date);
                if (date=="ok_ad"){
                    //请求成功跳转页面
                    location.href="${pageContext.request.contextPath}/admin/toIndex.action";
                }else if (date=="ok_co"){
                    //请求成功跳转页面
                    location.href="${pageContext.request.contextPath}/coach/toIndex.action";
                }else if (date=="ok_me"){
                    //请求成功跳转页面
                    location.href="${pageContext.request.contextPath}/member/toIndex.action";
                }else {
                    layer.msg("账号或密码有误！");
                }
            },
            error:function (){
                //请求失败
                // alert("网络不稳定，请重试！");
                layer.msg("网络不稳定，请重试！！");
                <%--location.href="${pageContext.request.contextPath}/";--%>
            }
        });
    }
</script>
</body>
</html>
